package com.ewiqi.springsecuritydemo.contoller;

import org.springframework.security.access.annotation.Secured;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author fengyu.zhang
 * @date 2021/1/18 5:29 下午
 */
@RestController
@RequestMapping("/")
public class MyController {
    @Resource
    PasswordEncoder passwordEncoder;


    @RequestMapping("index")
    public String index() {
        return "index";
    }

    @RequestMapping("admin")
    @Secured("ROLE_admin")
    public String admin() {
        return "admin";
    }

    @RequestMapping("loginSuccess")
    public String loginSuccess() {
        return "success";
    }

    @RequestMapping("loginFailed")
    public String loginFailed() {
        return "failed";
    }

    @RequestMapping("pwd")
    public String pwd(String pwd) {
        return passwordEncoder.encode(pwd);
    }
}
